package com.zhieasy.service.impl;

import com.zhieasy.common.service.RedisService;
import com.zhieasy.service.CheckCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author 风亦未止
 * @date 2021/11/20 15:29
 */
@Service
public class CheckCodeServiceImpl implements CheckCodeService {
    @Autowired
    private RedisService redisService;

    @Value("${redis.database}")
    private String REDIS_BASE;
    @Value("${redis.key.studentId}")
    private String STUDENT_ID;

    /**
     * 过期时间
     */
    @Value("${redis.expire.authCode}")
    private long expireTime;

    @Override
    public void put(String studentId, Object o) {
        String key=REDIS_BASE+":"+STUDENT_ID+":"+studentId;
        redisService.set(key,o,expireTime);
    }

    @Override
    public Object get(String studentId) {
        String key=REDIS_BASE+":"+STUDENT_ID+":"+studentId;
        return redisService.get(key);
    }

    @Override
    public boolean remove(String studentId) {
        String key=REDIS_BASE+":"+STUDENT_ID+":"+studentId;
       return redisService.del(key);
    }
}
